//! 格式化器模块
//!
//! 提供日志事件的格式化功能，将 [`LogEvent`] 转换为字符串输出。
//!
//! ## 主要类型
//!
//! - [`Formatter`] - 格式化器 trait，定义格式化接口
//! - [`TextFormatter`] - 默认文本格式化器实现
//!
//! ## 输出格式
//!
//! 默认文本格式：`{time} [{level}] {target}: {message}`
//!
//! 示例输出：
//! ```text
//! 2025-12-01 10:30:45.123 [INFO ] my_app::module: 服务启动成功
//! ```
//!
//! ## 示例
//!
//! ```rust
//! use log4r::formatter::{Formatter, TextFormatter};
//! use log4r::{Level, LogEvent};
//!
//! let formatter = TextFormatter::new();
//! let event = LogEvent::new(Level::Info, "my_app", "Hello, world!");
//! let output = formatter.format(&event);
//! println!("{}", output);
//! ```

mod text;

#[cfg(feature = "color")]
mod colored;

pub use text::TextFormatter;

#[cfg(feature = "color")]
pub use colored::{cached_terminal_color_support, should_colorize, ColoredFormatter};

use crate::event::LogEvent;

/// 日志格式化器 trait
///
/// 所有格式化器必须实现此 trait，将 [`LogEvent`] 转换为字符串。
/// 实现必须满足 `Send + Sync` 以支持多线程环境。
///
/// # 示例
///
/// ```rust
/// use log4r::formatter::{Formatter, TextFormatter};
/// use log4r::{Level, LogEvent};
///
/// let formatter = TextFormatter::new();
/// let event = LogEvent::new(Level::Info, "my_app", "Hello, world!");
/// let output = formatter.format(&event);
/// assert!(output.contains("[INFO ]"));
/// assert!(output.contains("my_app:"));
/// assert!(output.contains("Hello, world!"));
/// ```
///
/// # 实现自定义格式化器
///
/// ```rust
/// use log4r::formatter::Formatter;
/// use log4r::LogEvent;
///
/// struct SimpleFormatter;
///
/// impl Formatter for SimpleFormatter {
///     fn format(&self, event: &LogEvent) -> String {
///         format!("[{}] {}", event.level, event.message)
///     }
/// }
/// ```
pub trait Formatter: Send + Sync {
    /// 将日志事件格式化为字符串
    ///
    /// # Arguments
    ///
    /// * `event` - 要格式化的日志事件
    ///
    /// # Returns
    ///
    /// 格式化后的字符串
    fn format(&self, event: &LogEvent) -> String;
}
